
vapp = new Vue(
		{
			el : '#app',
			data : {
				show_bar : true,		
				pageSizes : config.pageSizes,
				currentPageNbr : config.currentPageNbr,
				pageSize : config.defaultpageSize,
				totalRecords : 0,				
				rowDbFlag : false, // 行是否可以双击标识
				editable : [],// 编辑列数组			
				tmpEditableVal : '', // 临时存储数据				
				userlist : [],// 人员列表					
				realName : '',
				penName:'',
				deptName:'',
				
				defaultProps : {},
//				filterText : '',// 节点过滤
				curTreeId : '5',// 监控树的节点id
				curTreePid: '',
				curTreeLevel : '3',// 当前树的层级
				treeRootId : '0',// 树根节点
				treelist : [],// 部门树数组、		
						
				dlForm: false,
				operType:'',
				activeTab:'tab1',
				showRang: '',
				deptAdjust: true,
				khSet: true,
				addEnable: false,
				
				backUp: false,
				curDeptId:'',
				kpPerson:'',
				kpJoin:'',
				dutyCode:'',
//				taskNum:'',
//				kpClass:'',
				duties: [],
				duties2:[],
				details:[],
				ids:[],
				multi: true,
				addshow: '0',
				msg:'',
				cascaderdeptOpt:{  			
					 showallevels:true,  //false 仅显示一级  true 显示多级  	
					 changeonselect:true,//若需要允许用户选择任意一级选项，则可将change-on-select赋值为true ; false 只能选择最后一级
					 clearable:false,//可清除
					 filterable:true,//将filterable赋值为true即可打开搜索功能
					 defaultProps: {
						children : 'children',
						label : 'label',
						value : 'id',
						expandTrigger: 'hover'
							
					 },
				 },    		
				 cascaderdept:{  		    
					 depts:[],   	
					 curdept:[],
					 operdept:[],
					 deptvalue:[] //默认值通过数组的方式指定 curdept
				 },  	
				 
				form: {
					  curDeptFlag:true,
		    		  operDeptFlag:true,
		    		  
					  userid:'',
					  username:'',
					  userNameC:false,
					  realname:'',
					  penname:'',
                      sex:'',
                      rank:'',
                      roles:[],
                      curDeptLevel:'',
                      curDeptNameC:false,
                      curDeptName:'',
                      curDeptId:'',
                      operDeptNameC:true,
					  sexlist:[],
					  ranklist:[],
					  ranks:[],  //实际显示ranklist
					  rolelist:[], 
					  roles:[],
					  sex: '',
					  displayOrder: '',
					  kpPerson: '',
					  dutyFlag:'',
					  phone:'',
					  kpJoin:'',
//					  taskNum:'',
					  dutyCode:'',
					  dutyCode2:[],
//					  kpClass:'',
					  deptCode:'',
					  groupCode:'',
					  
					  dutyflist:[],
					  kpplist:[],
					  kpjlist:[],
//					  jxkplist:[],
					  birth: new Date(),
//					  errMsg:'',
					  kppDisable: false,
					  psscope:[],  //''
					  showScope: false
		        },
		        scopes:[],
		    
		        treeOperType:'',
		    	dlTreeForm: false,
		    	
		    	treeForm: {
		    		
		    		openTreeCurDeptCnt :0,
			    	openTreeOperDeptCnt :0,
		    		defaultProps : {},
					filterText : '',// 节点过滤
					curTreeId : '',// 监控树的节点id
					curTreeLevel : '',// 当前树的层级
					treeRootId : '0',// 树根节点
					treelist : [],// 部门树数组、	    		
		    		id:'',
		    		deptCode:'',
		    		groupCode:'',
		    		deptLevel:''
		    	},
		    	uploader: {},
		        fileNo:'',
		        loading: false
			},
			
			created : function() {

				tools.loadDiv();
				

			},
			mounted : function() {
				  var that = this; 
					 userEx.getUserInfo(function(data){
				        
				         
				          tools.checkPriv(data.userinfo.privNames,"user_manage");
				         
				     });  
				this.initData();

			},
			
			
			watch : {
//				filterText : function() {
//
//					this.$refs.tree.filter(this.filterText);
//					// alert(this.filterText);
//				},
//				currentPageNbr : function() {
//					//alert(this.currentPageNbr);
//					this.getUserList();
//				},
//				
//				
//				pageSize : function() {
//					// alert(this.currentPageNbr);
//					if(this.currentPageNbr==1){
//						this.getUserList();
//			    	}else{
//			    		this.currentPageNbr=1;
//			    	}
//					
//				},
				curTreeId : function() {
					var that = this;
					// alert(this.currentPageNbr);
					//this.getUserList();
					if(this.curTreeLevel=="1"){
						this.addEnable = false;
					}else if(this.addShow=="1"){
						this.addEnable = true;
						// 调 存储过程
//						tools.ajaxRequestAsync("../../pub/userInfo/showmsg.mvc",{"curDeptId": this.curTreeId},
//						function(v) {
//							if (v.respCode == "0"){
//								that.msg = v.respDesc;	
//							} else {
//								that.msg = "";			
//							}
//						});				
						
					}else{
						this.addEnable = false;
					}
				},
//				"form.dutyCode":function(e){
//					//console.log(e);
//					if(e=="12"){
//						this.form.dutyFlag="1";
//					}else{
//						this.form.dutyFlag="0";
//					}
//				},
				

			},
			methods : {
				
				dftDate:function(date){
					var y = date.getFullYear()-22;
					var str = y+"/"+(date.getMonth()+1)+"/"+date.getDate();
					return new Date(str);
				},
				
				
//				getRws: function(value){
//					for(var i=0;i<this.details.length;i++){
//						var item = this.details[i];
//						if(item.gwid==value){
//							this.form.taskNum= item.gjrws;
//							break;
//						}
//					}				
//					
//				},
				
				//bar 折叠 公共可拷贝
				toggle_bar : function() {
					if (this.show_bar) {
						this.show_bar = false;
					} else {
						this.show_bar = true;
					//	vapp.$refs.tree.filter(this.filterText);
					}
				},
				
				// 改变当前页方法 公共可拷贝
				handleCurrentChange : function(currentPageNbr) {
					this.currentPageNbr = currentPageNbr;
//					console.log("当前页" + this.currentPageNbr);
					this.rowDbFlag = true;
					this.getUserList();
					
				},
				// 改变当前页记录数方法 公共可拷贝
				handleSizeChange : function(pageSize) {
					this.currentPageNbr = 1;
					this.pageSize = pageSize;
//					console.log("每页" + this.pageSize);
					this.getUserList();
					this.rowDbFlag = true;
				},
				
				
				
				// 可以改变返回的某行的颜色 为行数据加索引 可拷贝
				tableRowClassName : function(rowVal) {
					// alert(JSON.stringify(rowVal.rowIndex));
					// alert(rowVal.rowIndex);
					rowVal.row.index = rowVal.rowIndex;
					// console.log(rowVal);

				},
				
				// 双击一行获取数据  公共可拷贝
				handleRowDbClick : function(row, event, column) {

					if (this.rowDbFlag) {

						this.tmpEditableStore(row);
						this.selectEditableData(row.index);
					}
					this.rowDbFlag = false;

				},
				changegw:function(o){
					//console.log(o);
					if(o=="12"){
						this.form.dutyFlag="1";
					}else{
						this.form.dutyFlag="0";
					}
					this.getDuties2();
					
					if(this.form.dutyCode2.length>0&&this.form.dutyCode2.indexOf(o)>-1){
						this.form.dutyCode2.splice(this.form.dutyCode2.indexOf(o),1);						
					}
					
				},
				// 初始化可编辑列
				initeditableData : function(len) {
					this.editable = new Array(len);
					for (var i = 0; i < len; i++) {
						this.editable[i] = false;
					}

				},
				
				
				// 只能选中一行
				selectEditableData : function(index) {

					this.initeditableData(this.editable.length);
					this.$set(this.editable, index, true);
				},

				// 取消选中行
				cancelEditableData : function(index) {

					this.$set(this.editable, index, false);
				},
				
				
				// 取消
				cancel : function(row) {
					this.tmpEditableReset(row);
					this.cancelEditableData(row.index);
					this.rowDbFlag = true;
//					console.log(row);

				},
				// 保存
				save : function(row) {
					this.cancelEditableData(row.index);
//					console.log(row);
					this.rowDbFlag = true;
				},

				// 将获取的数据临时存储
				tmpEditableStore : function(row) {

					this.tmpEditableVal = row.realName;

				},

				// 恢复原变量
				tmpEditableReset : function(row) {

					row.realName = this.tmpEditableVal;
					this.tmpEditableVal = '';

				},
				
				//初始化数据
				initData:function(){
					var that = this;
					this.showRang = tools.getConfig({"prop":"showRang"});
					this.form.birth = this.dftDate(this.form.birth);
					//if(this.showRang==0){
					//	this.form.rules.rank=[];
					//}
					this.getScopes();
					this.cascaderdept=tools.getDeptOpts(userExInfo.deptCode,"0","0");
					user.getUserInfo(function(data) {				
						that.treeRootId = data.userinfo.privDeptId;
//						console.log(JSON.stringify(data));
						var privNames = data.userinfo.privNames;
						if(privNames.indexOf("dept_adjust")<0){
							that.deptAdjust= false;
						}
						if(privNames.indexOf("user_kh_set")<0){
							that.khSet = false;
						}
						 
						that.curTreeId = data.userinfo.curDeptId; //data.userinfo.privDeptId								
						that.curTreeLevel = data.userinfo.curDeptLevel; //data.userinfo.privDeptLevel
						that.deptName=data.userinfo.curDeptName;	// data.userinfo.privDeptName
						that.ids.push("'"+that.curTreeId+"'");
						that.getTreeList();						
						
						that.getUserList();
						
						that.getTreeList2();
						
						//that.getOptionInfo();
					});
					this.getDuties();
					this.initUploader();
				},
				
				getDuties:function(){
					var that = this;
					tools.ajaxRequestAsync(
							"../../pub/kh/khgwpzGroupList",
							{},
							function(v) {
								//alert(JSON.stringify(v));
								if (v.respCode == "0")
								{
									that.duties = v.mastlist;
									for(var i=0;i<v.mastlist.length;i++){
										that.details.push.apply(that.details,v.mastlist[i].detaillist);
									}								
								} else {
										
								}
					});					
				},				
				
				getDuties2:function(){
					var that = this;
					this.duties2 = [];
					var duties = JSON.parse(JSON.stringify(this.duties));
					duties.forEach(function(item,idx){
							if(item.detaillist.length>0){
								var list = [];
								item.detaillist.forEach(function(obj,i){
									if(obj.gwid!=that.form.dutyCode){
										list.push(obj);
									}
								});		
								item.detaillist = list;
							}
							that.duties2.push(item);						
					 });					
					
				},
				
				getOptionInfo:function(){
					var that = this;
					tools
					.ajaxRequestAsync(
							"../../pub/userInfo/getOptionInfo",
							{},
							function(v) {

								alert(JSON.stringify(v));
								if (v.respCode == "0")
								{
										that.form.sexlist = v.sexlist;
										that.form.ranklist=v.ranklist;
										alert(JSON.stringify(v.ranklist));
										that.form.rolelist=v.rolelist;
										alert(JSON.stringify(v.rolelist));
										alert(JSON.stringify(v.sexlist));
									} else {
										
									}
							});
				},
				
				getOptionInfo2:function(){
					var that = this;
					var v=tools.ajaxRequest("../../pub/userInfo/getOptionInfo",{});
					
					//alert(JSON.stringify(v));
					if (v.respCode == "0")
					{
							that.form.sexlist = v.sexlist;
							that.form.ranklist=v.ranklist;
							//alert(JSON.stringify(v.ranklist));
							that.form.rolelist=v.rolelist;
							//alert(JSON.stringify(v.rolelist));
//							if(that.form.){
//								
//							}
							that.form.dutyflist=v.dutyflist;
							that.form.kpplist = v.kpplist;
							that.form.kpjlist = v.kpjlist;
//							that.form.jxkplist = v.jxkplist;
							
						} else {
							
						}
		
				},
				 //用户列表方法				
				getUserList : function() {
					var that = this;
					 console.log(this.curTreeId);
					 console.log(this.curTreeLevel);
					var postdata = {
						"deptId" : this.curTreeId,
						"deptIds": this.ids.join(","),
						"deptLevel" : this.curTreeLevel,
						"currentPageNbr" : this.currentPageNbr,
						"pageSize" : this.pageSize,
						"realName" : this.realName
					};

//					 console.log(JSON.stringify(postdata));
					
					var v = tools.ajaxRequest("../../pub/userInfo/userInfoList",postdata);
//					console.log(JSON.stringify(v));
					if (v.respCode == "0"&& (v.userInfoList != undefined ? v.userInfoList.length: 0)) {
						this.addShow = v.userInfoAdd.show;
						this.userlist = v.userInfoList;
						this.totalRecords = v.page.totalRecords;
						this.initeditableData(v.userInfoList.length);
					} else {
						this.userlist = [];
						this.totalRecords =0;
						this.currentPageNbr=1;
						this.addShow = (v.userInfoAdd.show==undefined?"0":v.userInfoAdd.show);
					}

				},
				
				getScopes:function(){
					// 获取评审范围
					this.scopes=gjly;					
					
				},
				// checkbox 多选
				handleSelectionChange : function(row) {
					// alert(JSON.stringify(row));
//					console.log(row);

				},

				// formatterUserName 格式化指定列
				formatterUserName : function(row, column) {
					// alert(JSON.stringify(row));
					// console.log(row);
					return row.userName;
				},

				
				// 修改用户信息方法
				edit : function(row) {
					// alert(JSON.stringify(row));

//					console.log(row);
			
					this.editForm("edit",row);
					

//					if (this.rowDbFlag) {
//
//						this.tmpEditableStore(row);
//						this.selectEditableData(row.index);
//					}
//					this.rowDbFlag = false;
				},

				// 重置用户密码方法
				reset : function(row) {
					var that=this;
					// alert(JSON.stringify(row));
					
					this.$confirm('是否重置用户 "'+row.realName+'" 密码 "111111" ?', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
				        	
				      
				        	var postdata = {
									"userId" : row.userId,				

								};
				        	
				    		tools
							.ajaxRequestAsync(
									"../../pub/userInfo/resetPwd",
									postdata,
									function(v) {

										if (v.respCode == "0") {
											that.getUserList();
											 that.$message({
										        	showClose: true,
										            type: 'success',
										            message: '密码重置成功!'
										          });								
										} else {
											 that.$message({
										        	showClose: true,
										        	 type: 'info',
										            message: '密码重置失败!'
										          });						
										}
									});
				          
				        }).catch(() => {
//				          this.$message({
//				        	showClose: true,
//				            type: 'info',
//				            message: '已取消重置密码'
//				          });          
				    });
//					console.log(row);

				},

				// 删除用户信息方法
				del : function(row) {
					var that=this;
					// alert(JSON.stringify(row));
					
					this.$confirm('此操作将永久删除 "'+row.realName+'" 用户信息, 是否继续?', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
				        	
				      
				        	var postdata = {
									"userId" : row.userId,				

								};
				        	
				    		tools
							.ajaxRequestAsync(
									"../../pub/userInfo/userInfoDel",
									postdata,
									function(v) {

										if (v.respCode == "0") {
											that.getUserList();
											 that.$message({
										        	showClose: true,
										            type: 'success',
										            message: '删除成功!'
										          });								
										} else {
											 that.$message({
										        	showClose: true,
										        	 type: 'info',
										            message: '删除失败!'
										          });						
										}
									});
				          
				        }).catch(() => {
//				          this.$message({
//				        	showClose: true,
//				            type: 'info',
//				            message: '已取消删除'
//				          });          
				    });
//					console.log(row);
					
					

				},
				
				//userlist 按姓名查找
				searchByRealName : function() {
//					this.currentPageNbr = 1;
//					this.getUserList();					
					this.curTreeLevel = this.treelist[0].deptLevel;
					this.curTreePid = this.treelist[0].pId;
					this.curTreeId = this.treelist[0].id;
					this.ids=[];
					this.ids.push("'"+this.treelist[0].id+"'");
					this.getChildIds(this.treelist[0]);
					this.deptName=this.treelist[0].label;
					this.getUserList();
				},
              
				
				// 部门树
				getTreeList : function() {
					var that = this;
					var defaultProps = {
						children : 'children',
						label : 'label',
						id : 'id'
					};
					this.defaultProps = defaultProps;
					
					var reqData = {
						"id" : this.treeRootId,
					};
					data = tools.ajaxRequest("../../pub/dept/deptTreeEx",
							reqData);
					this.treelist = data.tree;
//					console.log(this.treelist[0]);
//					this.ids.push("'"+this.treelist[0].id+"'");
					if(this.multi){
//						this.getChildIds(this.treelist[0]);
						this.getChildIds(this.getNode(this.curTreeId,this.treelist[0]));
					}	
					this.$nextTick(() => {
//						 this.$refs.tree.setCurrentKey(this.treelist[0].id); 
						 that.$refs.tree.setCurrentKey(that.curTreeId);
					});
					
				},
				getNode:function(id,root){
					var that = this;
					if(root.id==id){
						return root;
					}else{
						if(root.children!=undefined&&root.children.length>0){
							var exist = false;
							var node = {};
							for(var i=0;i<root.children.length;i++){	
								if(root.children[i].id==id){
									exist = true;
									node = root.children[i];
									break;
								}
							}
							if(exist){
								return node;
							}else{
								return that.getNode(id,root.children[i]);
							}
							
						}
					}					
				},			
               //单击节点事件
				handleNodeClick : function(data) {
					 //alert(JSON.stringify(data));
					// alert(data.id+"----"+data.deptLevel);
					this.currentPageNbr=config.currentPageNbr;				
					this.ids=[];
					this.ids.push("'"+data.id+"'");
					if(this.multi){
						this.getChildIds(data);
					}
					
					this.deptName=data.label;
					if(this.curTreeId!=data.id){
						this.realName="";
					}					
					this.curTreeLevel = data.deptLevel;
					this.curTreePid = data.pId;
					this.curTreeId = data.id;
					this.getUserList();
				},				

				getChildIds:function(data){
					var that = this;
					for(var i=0;i<data.children.length;i++){
						that.ids.push("'"+data.children[i].id+"'");
						if(data.children[i].children.length!=0){
						   that.getChildIds(data.children[i]);
						}
					}		
				},
				
				filterNode : function(value, data) {
					// alert(value);
					if (!value)
						return true;
					return data.label.indexOf(value) !== -1;
				},				
				
				handleClick: function(tab, event){
//			        console.log(tab, event);
			    },				
				
			    curDeptChg:function(value){
			    	// 参考 dlTreeSave
			    	var that =this;
			    	var arry = tools.deptchange(this.cascaderdept.curdept,this.cascaderdept.depts);
			    	this.form.curDeptId= tools.arrToStrParam(arry,1);
//					this.form.curDeptName=this.treeForm.curDeptName;
					this.form.deptCode = this.form.curDeptId;
					this.form.groupCode= "0"; //this.treeForm.groupCode;
					
					var level = this.getLevel(this.cascaderdept.depts);
					
//					this.treeForm.deptLevel = data.deptLevel;
//					 if(data.deptLevel=="3"){
//						 this.treeForm.deptCode=data.pId;
//						 this.treeForm.groupCode=data.id;
//					 }else{
//						 this.treeForm.deptCode=data.id;
//						 this.treeForm.groupCode='0';
//					 }	
					
					 if(this.showRang!=0){
						   this.form.ranks = this.form.ranklist.concat();
						   switch(level){
							   	 case '1': this.form.ranks.splice(1,3); 
							   		  break;
							   	 case '2': this.form.ranks.splice(2,2);
							   		  break;
							   	 case '3': this.form.ranks.splice(3,1);
							   		  break;
							   	 default: break;
						  }	
					   }
			    	
			    },
			    operDeptChg:function(value){
			    	var arry = tools.deptchange(this.cascaderdept.operdept,this.cascaderdept.depts);
			    	this.form.operDeptId= tools.arrToStrParam(arry,1);
//					this.form.operDeptName=this.treeForm.operDeptName;
			    	
			    },
			    
			    
			    getLevel:function(depts){
			    	var that = this;
			    	var level = "";
			    	depts.forEach(function(item){
						if(that.form.curDeptId==item.id){
							level = item.deptLevel;
						}else if(level==""&&item.children!=undefined&&item.children!=null&&item.children.length>0){
							level = that.getLevel(item.children);
						}
					});			
			    	return level;
			    },
			    
			    initUploader:function(){
			  		var that = this;
			  		this.uploader = WebUploader.create({
			  		    swf: '../../plugin/webuploader/Uploader.swf',
			  		    server: '../../pub/attach/uploadsingle',
			  		    pick: {
			              id: '#picker',
			              label: '选择文件',
			              multiple:false
			  		    },
			  		    resize: false,
			  		    duplicate:true,
			  		    accept: {
			              title: 'appendix',
			              extensions: "xls,xlsx",
			              mimeTypes: "*/*"
			  		    },
			            fileSizeLimit: 5 * 1024 * 1024, // 5M
			            auto:true
			  		});
			  		
			  		this.uploader.on( 'fileQueued', function( file ) {
//			  			that.fileName = file.name;
			  		});
			  		
			  		this.uploader.on('uploadBeforeSend', function( block, data ){  
//			  			that.fileNo= tools.getuuid(32, 16);
			  			var file = block.file;
			  		    data.fileSize=  file.size;
//			  		    data.fileNo = that.fileNo;
			  		    data.fileName = file.name;
			  		    data.fileType = file.type;
			  		    data.modeName = "用户录入";
			  		    data.folder= "/file/user";
			  		},2);  
			  		 
			  		this.uploader.on( 'uploadProgress', function( file, percentage ) {
			  		    that.loading = true;
			  		});
			  		
			  		this.uploader.on( 'uploadSuccess', function( file, response ) {
//			  	        console.log(response);
			  			var filePath = response.fileList[0].filePath;
//			  	        var fileId = response.fileList[0].fileId;
//			  	        var fileNo = response.fileList[0].fileNo;
//			  	        var fileName = response.fileList[0].fileName;
//			  	        that.onSearch();  	  			
			  	        // 解析xlsx
			  			console.log(filePath);
			  			var reqData = {
			  				"path": filePath,
			  				"deptId": that.curTreeId	  				
			  			};
			  			
			  			tools.ajaxRequestAsync("../../pub/userInfo/importUsers",reqData,function(v) {
							if (v.respCode == "0") {
								if(v.failure.length>0){
									var msg = "部分用户导入失败 【"+v.failure+"】";
									that.showError(msg);  									
								}else{
									var msg = "用户导入成功!"+(v.respDesc=='ok'?"":"("+v.respDesc+")");
									that.$message({
								        showClose: true,
								        type: 'success',
								        message: msg
								    });
								}
								that.getUserList();
							}else { 
							   that.$message({
								   showClose: true,
								   type: 'info',
								   message: '用户导入失败!'
		        		       });						
							}
			  			}); 
			  			
			  		});

			  		this.uploader.on( 'uploadError', function( file ) {
			  			that.showError("导入失败");  
//			  			that.gjwfData = [];
			  		});
			  		
			  		this.uploader.on( 'uploadComplete', function( file ) {
			  			that.loading = false;
//			  			that.fileName ="";
			  		});
			  		
			  	},
			    importUser:function(){
			    	$("#picker input").click();
			    },
				editForm: function(operType,row) {
					var curDeptFlag="true";
					var operDeptFlag="true";
					this.getOptionInfo2();
                   // alert(this.curTreeLevel);
					var reqData = {
						"deptLevel":this.curTreeLevel,
						"deptId":this.curTreeId
					};
					var data = tools.ajaxRequest("../../pub/userInfo/deptConfig", reqData);
					 //alert(JSON.stringify(data));
					if(data.respCode=="0"){
						var info = data.list[0];
						if(data.list.length!=0){
							var list=[];
							list=tools.getArr(this.form.rolelist,"roleId",info.role_list);
							this.form.rolelist=list;
							this.form.roles=tools.strToArr(info.role_check,",");
							curDeptFlag=info.dept_change;
							operDeptFlag=info.dept_priv;
							if(curDeptFlag=="false")
							{
								this.form.curDeptFlag=false;
							}
							else
							{
							    this.form.curDeptFlag=true;	
							}
							if(operDeptFlag=="false")
							{
								this.form.operDeptFlag=false;
							}
							else
							{
								this.form.operDeptFlag=true;
							}
						}
						else
						{
//							 this.form.roles=[];
							 this.form.curDeptFlag=true;	
							 this.form.operDeptFlag=true;
						}
						
					}
					else
					{
						 this.form.roles=[];
						 this.form.curDeptFlag=true;	
						 this.form.operDeptFlag=true;
					}
					 //alert(operType+" "+JSON.stringify(data));
					//alert(JSON.stringify(this.form.roles));
				   this.operType=operType;
				 //  alert(operType+"  "+JSON.stringify(row));
				   if(this.operType=='edit')
				   {
					   this.curDeptId = row.deptId;
					   this.cascaderdept.curdept = tools.getsonToParent(this.curDeptId.toString(),this.cascaderdept.depts);					   
					   this.kpPerson= row.kpPerson==""?"0":row.kpPerson;
					   this.kpJoin= row.kpJoin==""?"1":row.kpJoin;
					   this.dutyCode=row.dutyCode;
//					   this.taskNum=row.taskNum;
//					   this.kpClass=row.kpClass;
					   this.form.userid=row.userId;
					   this.form.username=row.userName;
					   this.form.realname=row.realName;
					   this.form.penname = row.penName;
					   this.form.userNameC=true;
					   this.form.sex=row.sexType==""?"sex_1":row.sexType;
					   this.form.rank=row.rank;	
					   
					   this.form.roles=tools.strToArr(tools.strToSub(row.roleList,","),",");
					   
					   this.form.curDeptLevel = this.curTreeLevel;
					   this.form.curDeptNameC=true;
					   this.form.curDeptName=row.deptName;
					   this.form.curDeptId=row.deptId;
					   this.form.operDeptNameC=true;
					   this.form.operDeptName=row.operDeptName;
					   this.form.operDeptId=row.operDeptId;
					   this.form.displayOrder = row.displayOrder;
					   var birth = row.birth;
					   this.form.birth= (birth==""||birth==undefined)?this.dftDate(new Date()):new Date(birth.substr(0,4)+"/"+birth.substr(4,2)+"/"+birth.substr(6,2));
					   this.form.kpPerson= row.kpPerson==""?"0":row.kpPerson;
					   this.form.dutyFlag = row.dutyFlag==""?"0":row.dutyFlag;
					   this.form.phone = row.phone;
					   this.form.kpJoin = row.kpJoin==""?"1":row.kpJoin;
//					   this.form.taskNum = row.taskNum;
					   this.form.dutyCode= row.dutyCode;
					   this.getDuties2();
					   this.form.dutyCode2 = row.dutyOthers!=undefined&&row.dutyOthers!=''?tools.RmvComma(row.dutyOthers).split(","):[];
					   
//					   this.form.kpClass = row.kpClass==''?[]:row.kpClass.split(",");
					   this.form.deptCode = row.deptCode;
					   this.form.groupCode = row.groupCode;
					   
					   this.form.psscope = row.ps_range==""?[]:row.ps_range.split(",");  
					   
					   if(this.form.dutyFlag=="1"){
						   this.form.kppDisable = true;
						   this.form.showScope = true;
					   }else if(this.form.kpPerson!="0"){
						   this.form.kppDisable = false;
						   this.form.showScope = true;
					   }else{
						   this.form.kppDisable = false;
						   this.form.showScope = false;
					   }
					   
				   }
				   else
				   {
					   this.form.userid='';
					   this.form.username='';
					   this.form.userNameC=false;
					   this.form.realname='';
					   this.form.penname='';
					   this.form.sex="sex_1";
					   this.form.rank='';
					  // this.form.roles=[];
					   this.form.curDeptNameC=true;
					   
					   this.form.curDeptName=this.deptName;
					   this.form.curDeptId=this.curTreeId;
					   this.cascaderdept.curdept = tools.getsonToParent(this.form.curDeptId,this.cascaderdept.depts);
					   this.form.curDeptLevel = this.curTreeLevel;
					   
					   this.form.operDeptNameC=true;
					   this.form.operDeptName='';
					   this.form.operDeptId='';
					   this.form.birth= this.dftDate(new Date());
					   this.form.displayOrder='';
					   this.form.kpPerson='0';
					   this.form.dutyFlag ="0";
					   this.form.phone = "";
					   this.form.kpJoin = "1";
//					   this.form.taskNum = "";
					   this.form.dutyCode= "";
					   this.getDuties2();
					   this.form.dutyCode2 = [];
					   
//					   this.form.kpClass=[];
					   if(this.curTreeLevel=="3"){
						   this.form.deptCode=this.curTreePid;
						   this.form.groupCode=this.curTreeId;
					   }else{
						   this.form.deptCode=this.curTreeId;
						   this.form.groupCode="0";
					   }
					   
					   this.form.kppDisable = false;
					   this.form.showScope = false;
					   this.form.psscope = [];
					   
					   this.backUp = true;
				   }
				   
				   if(this.showRang!=0){
					   this.form.ranks = this.form.ranklist.concat();
					   if(this.operType=='edit'){
						   switch(row.dept_level){ //this.form.curDeptLevel
						   	case '1': this.form.ranks.splice(1,3); 
						   		  break;
						   	case'2': this.form.ranks.splice(2,2);
						   			 
						   		  break;
						   	 case'3': this.form.ranks.splice(3,1);
						   	 	break;
						   	 default: break;
						   }
					   }else{
						   switch(this.form.curDeptLevel){
						   	case '1': this.form.ranks.splice(1,3);
						   			 this.form.rank = this.form.ranks[0].code;
						   		  break;
						   	case'2': this.form.ranks.splice(2,2);
						   			this.form.rank = this.form.ranks[0].code;
						   		  break;
						   	 case'3': this.form.ranks.splice(3,1);
						   	 		this.form.rank = this.form.ranks[2].code;
						   		  break;
						   	 default: break;
						   }
					   }
					   if(this.showRang==2){
						   this.form.operDeptFlag = false;
					   }
				   }
				   
				   
				   this.dlForm=true;
				   
				},
				
				dutyChg:function(value){
					if(value=="1"){
						this.form.kpPerson = "1";
						this.form.kppDisable = true;
						this.form.showScope=true;
						this.form.psscope = [];
					}else {
						this.form.kppDisable = false;
						if(this.form.kpPerson!="0"){
							this.form.showScope=true;
							this.form.psscope = [];
						}else{
							this.form.showScope=false;
							this.form.psscope = [];
						}
						
					}
					
				},
				kppChg:function(value){
					if(value!="0"){
						this.form.showScope=true;
						this.form.psscope = [];
					}else{
						this.form.showScope=false;
						this.form.psscope = [];
					}
					
				},
				
				dlClose: function(formName) {
					 this.activeTab = "tab1";
					 this.dlReset(formName);
					 this.form.roles=[];
					 this.dlForm=false;
					
				},
				
				
				
				dlCancel: function(formName) {
					 
					 this.activeTab = "tab1";
					 this.dlForm=false;
					 this.dlReset(formName);
					 this.form.roles=[];
				},
				
				dlReset: function(formName) {
					  this.$refs[formName].resetFields();
				},
				
				
				dlCheck:function(){
					var backStr={"valid":true,"msg":"验证成功","tab":"tab1"};
					var uname=this.form.username;
					if(uname.trim()==""){
						backStr.valid=false;
						backStr.msg="请输入登录名";
						backStr.tab="tab1";
						return backStr;
					}
					if(this.operType == "add"||this.operType == "edit"){
						 var postdata = {
						 	"userId" : this.form.userid,				
							"userName" :  this.form.username,	
 						 };
 						 var data = tools.ajaxRequest("../../pub/userInfo/checkUserName",postdata);
						 if (data.respCode == "0") {
						 	backStr.valid=false;
							backStr.msg="该用户名已经被占用";
							backStr.tab="tab1";
							return backStr;
						 } 
					}
					var rname= this.form.realname;
					if(rname.trim()==""){
						backStr.valid=false;
						backStr.msg="请输入姓名";
						backStr.tab="tab1";
						return backStr;
					}else if(rname.length<2||rname.length>25){
						backStr.valid=false;
						backStr.msg="姓名长度在2到25个字符";
						backStr.tab="tab1";
						return backStr;
					}
					
					var pname = this.form.penname;
					if(pname.trim()!=""&&(pname.length<2||pname.length>25)){
						backStr.valid=false;
						backStr.msg="笔名长度在2到25个字符";
						backStr.tab="tab1";
						return backStr;
					}

					if(this.form.roles.length==0){
						backStr.valid=false;
						backStr.msg="至少选一个用户角色";
						backStr.tab="tab1";
						return backStr;
					}

					if(this.form.rank==""){
						backStr.valid=false;
						backStr.msg="请选择查看范围";
						backStr.tab="tab1";
						return backStr;
					}

					var dOrder = this.form.displayOrder;
					var regPos = /^-?\d+$/;
					if (dOrder!=""&&!regPos.test(dOrder)) {
						backStr.valid=false;
						backStr.msg="显示顺序必须为整数";
						backStr.tab="tab1";
						return backStr;
					}


					if(this.form.sex==""){
						backStr.valid=false;
						backStr.msg="请选择性别";
						backStr.tab="tab2";
						return backStr;
					}

//					if(this.form.dutyCode==""){
//						backStr.valid=false;
//						backStr.msg="请选择岗位";
//						backStr.tab="tab2";
//						return backStr;
//					}

					var phone = this.form.phone;
					var regPos = /^\d+$/;
					if (phone!=""&&!regPos.test(phone)) {
						backStr.valid=false;
						backStr.msg="电话必须为数字";
						backStr.tab="tab2";
						return backStr;												
					}

//					var taskNum = this.form.taskNum;
//					var regPos = /^\d+$/;
//					if(taskNum!=""&&!regPos.test(taskNum)){
//						backStr.valid=false;
//						backStr.msg="任务数必须为非负整数";
//						backStr.tab="tab2";
//						return backStr;		
//					}

					return backStr;

				},

				dlSave: function(formName) {
					//  部门负责人  是/否  更新 dept表
					//	所属部门调整    考核人员设置  需备份    
					
					
					var that=this;
					var backStr = this.dlCheck();
					if(!backStr.valid){
						this.showError(backStr.msg);
						this.activeTab=backStr.tab;
						return false;
					}
				    
//				    if(this.form.kpJoin=="1"){
//				       var postdata = {
//							"userId" : this.form.userid,				
//							"deptId":  this.form.curDeptId,	
////							"num": this.form.taskNum
//						};						
//						var data= tools.ajaxRequest("../../pub/userInfo/chkTaskNum.mvc",postdata);
//						if(data.respCode == "0"&&data.valid=="false"){
//							this.showError("超过所在部门可分配任务数 ("+data.rest+")");
//							return false;
//						}else if(data.respCode == "-1"){
//						    this.showError("访问数据库失败");
//							return false;
//						}			
//				    }
				        	  
				    if(this.form.curDeptId!=this.curDeptId||this.form.kpPerson!=this.kpPerson||this.form.kpJoin!=this.kpJoin||
				        			this.form.dutyCode!=this.dutyCode){ //||this.form.taskNum!=this.taskNum ||this.form.kpClass!=this.kpClass
				        this.backUp=true;
				    }
//				    var kpClass = this.form.kpClass;
				    var scope = "";
				    if(this.form.showScope){
				    	if(this.form.psscope.length>0){
				    		scope = this.form.psscope.join(",");
				    	}else{
				    		var scps = this.scopes.map(function(item){
					    		return item.code;
					    	});
					    	scope = scps.join(",");
				    	}
				    }else{
				    	var scps = this.scopes.map(function(item){
				    		return item.code;
				    	});
				    	scope = scps.join(",");
				    }
				    
				    
				    var postdata = {
				        "userId" : this.form.userid,
					  	"addDeptId" :  this.form.curDeptId,
					  	"operDeptId" : this.form.operDeptId,
					  	"operDeptName": this.form.operDeptName,
					  	"userName" : this.form.username,
					  	"realName" : this.form.realname,
					  	"penName": this.form.penname,
					  	"sexcode" : this.form.sex,
					  	"rankcode" : this.form.rank,
					  	"roleList" :tools.arrToStr(this.form.roles),		
					  	"deptCode": this.form.deptCode,
					  	"groupCode": this.form.groupCode,
					  	"displayOrder": this.form.displayOrder,
					  	"dutyFlag": this.form.dutyFlag,
					  	"phone": this.form.phone,
					  	"kpPerson": this.form.kpPerson,
					  	"kpJoin": this.form.kpJoin,
					  	"dutyCode": this.form.dutyCode,
					  	"dutyOthers": this.form.dutyCode2.length>0?","+this.form.dutyCode2.join(",")+",":"",
//					  	"taskNum":this.form.taskNum,
//					  	"kpClass": kpClass==[]?"":kpClass.join(","),
					  	"birth": util.formatTime(this.form.birth,"yyyyMMdd"),
					  	"backUp": this.backUp,
					  	"range": scope
					};
//				     console.log(postdata);
					 tools.ajaxRequestAsync("../../pub/userInfo/userInfoSave",postdata,	function(v) {
						if (v.respCode == "0") {
							that.getUserList(); 
							that.$message({
						        	showClose: true,
						            type: 'success',
						            message: '用户保存成功!'
						    });	
						    that.dlClose('form');
						}else if(v.respCode == "1"){
							that.$message({
						       	showClose: true,
						    	type: 'info',
							    message: v.respDesc
        		          });						
						} else {
						   that.$message({
							       	showClose: true,
							    	type: 'info',
								    message: '用户保存失败!'
	        		          });						
											}
						   that.backUp = false;
					}); 
				          
					 
				},
				
				/**
				 * dg tree
				 */
				getTreeList2 : function() {
					var defaultProps = {
						children : 'children',
						label : 'label',
						id : 'id'
					};
					this.treeForm.defaultProps = defaultProps;

					var reqData = {
						"id" : this.treeForm.treeRootId,
					};
					data = tools.ajaxRequest("../../pub/dept/deptTreeEx",
							reqData);
					if(arguments[0]!=undefined){
						data = data[0].children;
						this.treeForm.treelist = data;
					}else{
						this.treeForm.treelist = data;
					}					
				},
				
				
				dlTreeGetDeptName : function(node,data)
				
				{
					
					if("curDept"==this.treeOperType)
					{
						 this.treeForm.curDeptId=data.id;
						 this.treeForm.curDeptName=node.label;
					    // this.treeForm.id=data.id;
						// this.form.curDeptName=node.label;
						 this.treeForm.deptLevel = data.deptLevel;
						 if(data.deptLevel=="3"){
							 this.treeForm.deptCode=data.pId;
							 this.treeForm.groupCode=data.id;
						 }else{
							 this.treeForm.deptCode=data.id;
							 this.treeForm.groupCode='0';
						 }						 
					}
					else if("operDept"==this.treeOperType)
					{
						 this.treeForm.operDeptId=data.id;
						 this.treeForm.operDeptName=node.label;
						 //this.treeForm.id=data.id;
						 //this.form.operDeptName=node.label;
					}
					
					//alert("treeForm.id="+this.treeForm.id+";id="+data.id+";label="+node.label);
				},
				
				
				dlTreeFrom: function(operType) {	
					if("curDept"==operType){
						this.getTreeList2('withoutroot');
					}else{
						this.getTreeList2();
					}						
					
					this.dlTreeForm=true;
					
					this.treeOperType=operType;
				 
					if("curDept"==operType )
					{
						if(this.treeForm.openTreeCurDeptCnt=="0")
						{
							
				            	this.treeForm.id= this.form.curDeptId.toString();
							    this.treeForm.curDeptName=this.form.curDeptName;
							    this.treeForm.curDeptId=this.form.curDeptId;
						}
						else
						{
							this.treeForm.id=this.treeForm.curDeptId;
							
							
						}
						this.treeForm.openTreeCurDeptCnt++;
						
						
						
					}
					
					 if("operDept"==operType )
					{
						
						 if(this.treeForm.openTreeOperDeptCnt=="0")
						 {
							 this.treeForm.id=this.form.operDeptId; 
							 this.treeForm.operDeptName=this.form.operDeptName;
							 this.treeForm.operDeptId=this.form.operDeptId;
						 }
						 else
						 {
							 this.treeForm.id=this.treeForm.operDeptId;
						 }
						 this.treeForm.openTreeOperDeptCnt++;
						 //this.treeForm.operDeptId=this.form.operDeptId;
						
						
					}
					
				},
				
			   
				dlTreeClose: function() {
					
					 this.treeForm.openTreeCurDeptCnt=0;
					 this.treeForm.openTreeOperDeptCnt=0;
					 this.dlTreeForm=false;
					
				},
				
				
				
				dlTreeCancel: function(formName) {
					 
					 this.dlTreeForm=false;
					
				},
				
				
					
				dlTreeSave: function() {
					var that=this;
					
					// 软件开发     dept_code 存今晚网络  group_code 软件开发
					// 今晚网络    dept_code 存今晚网络   group_code '0'
					if("curDept"==this.treeOperType)
					{
						 this.form.curDeptId= this.treeForm.curDeptId;
						 this.form.curDeptName=this.treeForm.curDeptName;
						 this.form.deptCode = this.treeForm.deptCode;
						 this.form.groupCode= this.treeForm.groupCode;
						 
						 if(this.showRang!=0){
							   this.form.ranks = this.form.ranklist.concat();
							  
							   switch(this.treeForm.deptLevel){
							   	 case '1': this.form.ranks.splice(1,3); 
							   		  break;
							   	 case '2': this.form.ranks.splice(2,2);
							   		  break;
							   	 case '3': this.form.ranks.splice(3,1);
							   		  break;
							   	 default: break;
							   }							   
						   }
					}
					else if("operDept"==this.treeOperType)
					{
						 this.form.operDeptId=this.treeForm.operDeptId;
						 this.form.operDeptName=this.treeForm.operDeptName;
						 //this.treeForm.id=data.id;
						 //this.form.operDeptName=node.label;
					}
					
				    this.dlTreeForm=false;
					//alert(JSON.stringify(this.$refs.treeForm.getCurrentNode())); 
				},
				
				showError: function(info){
					var i = (info==undefined?"加载数据错误":info);
					this.$alert(i, '系统错误', {
				          confirmButtonText: '确定'
				    });	
				},
				exportForm:function(){
//					console.log(that.userlist);
					var fields={"userName":"用户名","realName":"姓名","roleListName":"角色"};
					this.exportJSON(this.userlist,fields);
				},
				exportJSON:function(data,fields){
					var exData = [];
					for(var i=0;i<data.length;i++){
						var obj={};
						var jso =data[i];
						for(var o in fields){
							if(jso[o]!=undefined){
								var name = fields[o];
								obj[name] = jso[o];
							}
						}
						exData.push(obj);
					}
					
//					tools.JSONToExcelConvertor("我的excel",exData);
					this.JSONToExcel(exData,'exp','用户管理');
				},				
				
				JSONToExcel:function(json,id,sheet,type){
					var that = this;
		            var tmpdata = json[0];
		            json.unshift({});
		            var keyMap = []; //获取keys
		            for (var k in tmpdata) {
		                keyMap.push(k);
		                json[0][k] = k;
		            }
		            var tmpdata = [];//用来保存转换好的json 
		                json.map((v, i) => keyMap.map((k, j) => Object.assign({}, {
		                    v: v[k],
		                    position: (j > 25 ? that.getCharCol(j) : String.fromCharCode(65 + j)) + (i + 1)
		                }))).reduce((prev, next) => prev.concat(next)).forEach((v, i) => tmpdata[v.position] = {
		                    v: v.v
		                });
		                var outputPos = Object.keys(tmpdata); //设置区域,比如表格从A1到D10
		                tmpdata["A1"].s = { font: { sz: 14, bold: true, color: { rgb: "FFFFAA00" } }, fill: { bgColor: { indexed: 64 }, fgColor: { rgb: "FFFF00" } } };//<====设置xlsx单元格样式
//		                tmpdata["!merges"] = [{
//		                    s: { c: 1, r: 0 },
//		                    e: { c: 4, r: 0 }
//		                }];
		                var tmpWB = {
		                    SheetNames: [sheet], //保存的表标题
		                    Sheets:{}
		                };
		                tmpWB.Sheets[sheet] = Object.assign({},
	                       tmpdata, //内容
	                            {'!ref': outputPos[0] + ':' + outputPos[outputPos.length - 1] //设置填充区域
	                    });
		                
		                tmpDown = new Blob([that.s2ab(XLSX.write(tmpWB, 
		                    {bookType: (type == undefined ? 'xlsx':type),bookSST: false, type: 'binary',cellStyles: true}//这里的数据是用来定义导出的格式类型
		                    ))], {
		                    type: ""
		                }); //创建二进制对象写入转换好的字节流
			            var href = URL.createObjectURL(tmpDown); //创建对象超链接
			            document.getElementById(id).href = href; //绑定a标签
			            document.getElementById(id).click(); //模拟点击实现下载
			            setTimeout(function() { //延时释放
			                URL.revokeObjectURL(tmpDown); //用URL.revokeObjectURL()来释放这个object URL
			            }, 100);
				},
		        s2ab: function(s) { //字符串转字符流
		            var buf = new ArrayBuffer(s.length);
		            var view = new Uint8Array(buf);
		            for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
		            return buf;
		        },
		        getCharCol:function(n) {
		            let temCol = '',
		            s = '',
		            m = 0;
		            while (n > 0) {
		                m = n % 26 + 1;
		                s = String.fromCharCode(m + 64) + s;
		                n = (n - m) / 26;
		            }
		            return s;
		        },
		        
		        showError: function(info){
		            var i = (info==undefined?"加载数据错误":info);
		            this.$alert(i, '系统错误', {
		                 confirmButtonText: '确定'
		            }); 
		        },
				
			}
			

		});
